<template>
  <div>
    <bpm-c-form>
      <bpm-c-block :ptitle="inputTitle[0]"
                   :preadonly="inputReadonly[0]"
                   :pinputtype="inputType[0]"
                   :pline="inputLine[0]"
                   :validateExp="validateExp[0]"
                   v-model="selectedGridInfo[gridShowInfo[0]]"
                   @valueChanged="setSelectedGridInfoCellIndex($event,0)"
      />
      <bpm-c-block :ptitle="inputTitle[1]"
                   :preadonly="inputReadonly[1]"
                   :pinputtype="inputType[1]"
                   :pline="inputLine[1]"
                   :validateExp="validateExp[1]"
                   v-model="selectedGridInfo[gridShowInfo[1]]"
                   @valueChanged="setSelectedGridInfoCellIndex($event,1)"
      />
    </bpm-c-form>
    <bpm-c-form>
    <bpm-c-block :ptitle="inputTitle[2]"
                 :preadonly="inputReadonly[2]"
                 :pinputtype="inputType[2]"
                 :pline="inputLine[2]"
                 :validateExp="validateExp[2]"
                 v-model="selectedGridInfo[gridShowInfo[2]]"
                 @valueChanged="setSelectedGridInfoCellIndex($event,2)"
    />
    <bpm-c-block :ptitle="inputTitle[3]"
                 :preadonly="inputReadonly[3]"
                 :pinputtype="inputType[3]"
                 :pline="inputLine[3]"
                 :validateExp="validateExp[3]"
                 v-model="selectedGridInfo[gridShowInfo[3]]"
                 @valueChanged="setSelectedGridInfoCellIndex($event,3)"
    />
    </bpm-c-form>
    <bpm-c-form>
    <bpm-c-block :ptitle="inputTitle[4]"
                 :preadonly="inputReadonly[4]"
                 :pinputtype="inputType[4]"
                 :pline="inputLine[4]"
                 :validateExp="validateExp[4]"
                 v-model="selectedGridInfo[gridShowInfo[4]]"
                 @valueChanged="setSelectedGridInfoCellIndex($event,4)"
    />
    <bpm-c-block :ptitle="inputTitle[5]"
                 :preadonly="inputReadonly[5]"
                 :pinputtype="inputType[5]"
                 :pline="inputLine[5]"
                 :validateExp="validateExp[5]"
                 v-model="selectedGridInfo[gridShowInfo[5]]"
                 @valueChanged="setSelectedGridInfoCellIndex($event,5)"
    />
    </bpm-c-form>
    <bpm-c-form>
    <bpm-c-block :ptitle="inputTitle[6]"
                 :preadonly="inputReadonly[6]"
                 :pinputtype="inputType[6]"
                 :pline="inputLine[6]"
                 :validateExp="validateExp[6]"
                 v-model="selectedGridInfo[gridShowInfo[6]]"
                 @valueChanged="setSelectedGridInfoCellIndex($event,6)"
    />
    <bpm-c-block :ptitle="inputTitle[7]"
                 :preadonly="inputReadonly[7]"
                 :pinputtype="inputType[7]"
                 :pline="inputLine[7]"
                 :validateExp="validateExp[7]"
                 v-model="selectedGridInfo[gridShowInfo[7]]"
                 @valueChanged="setSelectedGridInfoCellIndex($event,7)"
    />
    </bpm-c-form>
    <bpm-c-form>
    <bpm-c-block :ptitle="inputTitle[8]"
                 :preadonly="inputReadonly[8]"
                 :pinputtype="inputType[8]"
                 :pline="inputLine[8]"
                 :validateExp="validateExp[8]"
                 v-model="selectedGridInfo[gridShowInfo[8]]"
                 @valueChanged="setSelectedGridInfoCellIndex($event,8)"
    />
    </bpm-c-form>
    <!--v-model="selectedGridInfo[gridShowInfo[i]]"-->
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex'
export default {
  name: 'bpmDFeeChoose',
  model: {
    event: 'selectedGridInfoChanged'
  },
  props: {
    title: '',
    pselectType: {
      type: String,
      default: ''
    },
    validateExp: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    let inputLine = [2, 2, 2, 2, 2, 2, 2, 2, 1]
    let inputType = ['text', 'text', 'number', 'number', 'number', 'number', 'number', 'number', 'textarea']
    let inputKey = ['city', 'hotelsname', 'days', 'personNum', 'notaxamount', 'tax', 'billssum', 'actualremibursesum',  'remark']
    return {
      inputLine: inputLine,
      inputType: inputType,
      gridShowInfo: inputKey,
      selectedGridInfoCellIndex: -1
    }
  },
  computed: {
    ...mapState(['ssc', 'chooseDialogEnum', 'pageType', 'pageTypeEnum', 'lang']),
    inputTitle () {
      return [
        this.getLanguage('label.whBtStaydetails.city'),
        this.getLanguage('label.whBtStaydetails.hotelsname'),
        this.getLanguage('label.whBtStaydetails.days'),
        this.getLanguage('label.whBtStaydetails.personNum'),
        this.getLanguage('label.whBtStaydetails.notaxamount'),
        this.getLanguage('label.whBtStaydetails.tax'),
        this.getLanguage('label.whBtStaydetails.billssum'),
        this.getLanguage('label.whBtStaydetails.actualremibursesum'),
        this.getLanguage('label.whBtStaydetails.remark')
      ]
    },
    selectedGridInfo () {
      return this.$store.state.gridSelectRow.ssc.reimburse.whBtStayDetails
    },
    inputReadonly () {
      switch (this.pageType) {
        case this.pageTypeEnum.draft:
          return [false, false, false, false, false, false, true, true, false]
        case this.pageTypeEnum.approve:
          return [true, true, true, true, true, true, true, true, true]
        case this.pageTypeEnum.approveFee:
          return [false, false, true, false, false, true, true, true, true]
        case this.pageTypeEnum.view:
          return [false, false, false, false, false, true, true, false, false]
      }
    }
  },
  methods: {
    ...mapActions(['updateDataSscCachePaymentInfo']),
    setSelectedGridInfoCellIndex (v, i) {
      this.selectedGridInfoCellIndex = i
      if (this.pageType === this.pageTypeEnum.draft) {
        console.log('zzzzz', v, i)
        if (i === 4) {
          if (this.draftHotelGridCheckNotaxamount() === false) {
            return false
          }
        } else if (i === 5) {
          if (this.draftHotelGridCheckTax() === false) {
            return false
          }
        } else {
        }
      } else if (this.pageType === this.pageTypeEnum.approveFee) {
        if (i === 4) { // 不含税金额
          let resObj = this.onSubEditCell('StayTable', 2, this.$store.state.gridSelectIndex.whBtStayDetails, 8, this.selectedGridInfo[this.gridShowInfo[i]])
          if (!resObj.resultFlag) {
            this.alert(resObj.resultMes)
            return
          }
          console.log('stayFormatSaveData-------')
          let tarObj = this.$store.state.gridSelectRow.ssc.reimburse.whBtStayDetails
          tarObj.actualremibursesum = tarObj.notaxamount * 1 + tarObj.tax * 1
        } else if (i === 5) { // 税额
          let resObj = this.onSubEditCell('StayTable', 2, this.$store.state.gridSelectIndex.whBtStayDetails, 9, this.selectedGridInfo[this.gridShowInfo[i]])
          if (!resObj.resultFlag) {
            this.alert(resObj.resultMes)
          }
          let tarObj = this.$store.state.gridSelectRow.ssc.reimburse.whBtStayDetails
          tarObj.actualremibursesum = tarObj.notaxamount * 1 + tarObj.tax * 1
        }
      }
    },
    addClicked () {
    },
    updateClicked () {},
    deleteClicked () {},
    selectClick (i) {
      console.log(i)
      this.dialogVisible = i
    },
    selDialogClicked (aObj) {
      this.dialogVisible = -1
      console.log('choose', aObj)
    },
    setDialogClose () {
      this.dialogVisible = -1
    },
    checkValidate () {
      console.log(this.validateExp)
      if (!this.validateExp) {
        return {
          result: true
        }
      }
      for (let i in this.validateExp) {
        console.log(i)
        if (!this.validateExp[i] || !this.validateExp[i].flag || !this.validateExp[i].require) {
          continue
        }
        if (this.inputReadonly[i]) {
          continue
        }
        let info = this.selectedGridInfo[this.gridShowInfo[i]]
        if (!info) {
          return {
            result: false,
            title: this.inputTitle[i]
          }
        }
        if (this.inputType[i] === 'text' || this.inputType[i] === 'textarea') {
          if (info === '') {
            return {
              result: false,
              title: this.inputTitle[i]
            }
          }
        }
        if (this.inputType[i] === 'number') {
          if (this.pageType === this.pageTypeEnum.approveFee) continue
          if (info === '0' || isNaN(parseInt(info))) {
            return {
              result: false,
              title: this.inputTitle[i]
            }
          }
        }
      }
      return {
        result: true
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
